import { Dictionary } from "../type/dictionary";

export class Constant {
  static mapper: Dictionary = [];

  static mapperKey: Dictionary = [];

  static mapperValue: Dictionary = [];
}

export type Empty = new (...args: any[]) => {};

// export const Const = <T extends Empty>(constructor: T): T => {
//   return class extends constructor {
//     static mapper: Dictionary = Object.entries(constructor).map(entry => ({
//       key: entry[0],
//       value: entry[1]
//     }));
//   };
// };

export function Const<T extends Empty>(constructor: T): T {
  return class extends constructor {
    static mapper: Dictionary = Object.entries(constructor).map((entry) => ({
      key: entry[0],
      value: entry[1],
    }));

    static mapperKey: Dictionary = Object.entries(constructor).map((entry) => ({
      key: entry[0],
      value: entry[0],
    }));

    static mapperValue: Dictionary = Object.entries(constructor).map(
      (entry) => ({
        key: entry[1],
        value: entry[1],
      })
    );
  };
}

// export const Field = <T extends Empty>(key?: string) => (
//   constructor: T,
//   propertyName: string
// ) => {
//   const mapper = "mapper";
//   if (!constructor[mapper]) {
//     constructor[mapper] = [];
//   }

//   constructor[mapper].push({
//     key: key || propertyName,
//     value: constructor[propertyName]
//   });
// };

/**
 * @deprecated
 * share constant
 */
export function Field<T extends Empty>(key?: string) {
  return (constructor: T, propertyName: string) => {
    const mapper = "mapper";
    if (!constructor[mapper]) {
      constructor[mapper] = [];
    }

    constructor[mapper].push({
      key: key || propertyName,
      value: constructor[propertyName],
    });
  };
}
